import http from '@/utils/http'

export function getCategoryAPI() {
  return http({
    url: 'home/category/head'
  })
}
export function getBannerAPI(params = {}) {
  const { distributionSite = '1' } = params
  return http({
    url: 'home/banner',
    params: {
      distributionSite
    }
  })
}
export const findNewAPI = () => {
  return http({
    url: '/home/new'
  })
}
export const getHotAPI = () => {
  return http({ url: 'home/hot' })
}
/**
 * @description: 获取所有商品模块
 * @param {*}
 * @return {*}
 */
export const getGoodsAPI = () => {
  return http({
    url: '/home/goods'
  })
}

export const getCategoryBreadAPI = (id) => {
  return http({
    url: '/category',
    params: {
      id
    }
  })
}

/**
 * @description: 获取二级分类列表数据
 * @param {*} id 分类id 
 * @return {*}
 */

export const getCategoryFilterAPI = (id) => {
  return http({
    url: '/category/sub/filter',
    params: {
      id
    }
  })
}
/**
 * @description: 获取导航数据
 * @data { 
     categoryId: 1005000 ,
     page: 1,
     pageSize: 20,
     sortField: 'publishTime' | 'orderNum' | 'evaluateNum'
   } 
 * @return {*}
 */
export const getSubCategoryAPI = (data) => {
  return http({
    url: '/category/goods/temporary',
    method: 'POST',
    data
  })
}

// 商品详情
export const getDetail = (id) => {
  return http({
    url: '/goods',
    params: { id }
  })
}
/**
 * 获取热榜商品
 * @param {Number} id - 商品id
 * @param {Number} type - 1代表24小时热销榜 2代表周热销榜
 * @param {Number} limit - 获取个数
 */
export const fetchHotGoodsAPI = ({ id, type, limit = 3 }) => {
  return http({
    url: '/goods/hot',
    params: {
      id,
      type,
      limit
    }
  })
}

export const loginAPI = ({ account, password }) => {
  return http({
    url: '/login',
    method: 'POST',
    data: { account, password }
  })
}
// 加入购物车
export const insertCartAPI = ({ skuId, count }) => {
  return http({
    url: '/member/cart',
    method: 'POST',
    data: { skuId, count }
  })
}
// 获取购物车列表
export const findNewCartListAPI = () => {
  return http({
    url: '/member/cart'
  })
}
// 删除购物车
export const delCartAPI = (ids) => {
  return http({
    url: '/member/cart',
    method: 'DELETE',
    data: { ids }
  })
}
// 合并购物车
export const mergeCartAPI = (data) => {
  return http({
    url: '/member/cart/merge',
    method: 'POST',
    data
  })
}
// 获取详情
export const getCheckInfoAPI = () => {
  return http({
    url: '/member/order/pre'
  })
}
// 创建订单
export const createOrderAPI = (data) => {
  return http({
    url: '/member/order',
    method: 'POST',
    data
  })
}
// 获取订单
export const getOrderAPI = (id) => {
  return http({
    url: `/member/order/${id}`
  })
}
// 猜你喜欢
export const getLikeListAPI = ({ limit = 4 }) => {
  return http({
    url: '/goods/relevant',
    params: {
      limit
    }
  })
}

/*
params: {
  orderState:0,
  page:1,
  pageSize:2
}
*/
export const getUserOrder = (params) => {
  return http({
    url: '/member/order',
    method: 'GET',
    params
  })
}